<?php

namespace app\common\service;

use api\channel\ExtendChannleBase;
use api\channel\jutuike\ActivityJutuikeChannle;
use api\channel\jutuike\Union;
use api\channel\meituan\alliance\Seckill;
use app\common\facade\supplier\Supplier;
use app\model\BaseSupplier;
use app\model\CouponOrderSid;
use think\facade\Db;

/**
 * 美团分销联盟
 * 秒杀的   @var Seckill
 */
class MeituanPubJutuike extends ActivityJutuikeChannle
{
    protected $search_deals_url = 'http://api.act.jutuike.com/mtfx/search_deals';
    protected $cate_url = 'http://api.act.jutuike.com/mtfx/city_categories';

    /**
     * 获取商品列表
     * @param $params
     * @return mixed|void
     */
    public function searchDeals($params)
    {
        $postData = input('post.');

        $sid = (new CouponOrderSid())->generateNew(PRODUCT_METUAN_SERV);
        $params['sid'] = $sid;
        $params['pub_id'] = $this->pubId;
        $params['lng'] = !empty($postData['geo']['lng']) ? $postData['geo']['lng'] :0;
        $params['lat'] = !empty($postData['geo']['lat']) ? $postData['geo']['lat'] :0;
        $params['cityId'] = !empty($params['geo']['cityId']) ? $params['geo']['cityId'] :'';
        $params['radii'] = !empty($postData['geo']['radii']) ? $postData['geo']['radii'] :5000;
        $params['cat0Id'] = $params['cat0_id']??0;
        $params['shopIds'] = $params['shop_id']??0;
        $params['cat1Ids'] = $params['cat1_id']??0;
        $params['sortType'] = $params['sort_type']??0;
        $params['keyWords'] = $params['keyword']??'';

        $res = curlPost($this->search_deals_url, json_encode($params), [
            'Content-Type: application/json; charset=utf-8',
        ]);

        return json_decode($res,true);

    }

    public function cityCategories($cityId, $cat0Id = 0){

        $sid = (new CouponOrderSid())->generateNew(PRODUCT_METUAN_SERV);
        $params['pub_id'] = $this->pubId;
        $params['cityId'] = $cityId;
        $params['cat0Id'] = $cat0Id;
        $params['sid'] = $sid;

        $res = curlPost($this->cate_url, json_encode($params), [
            'Content-Type: application/json; charset=utf-8',
        ]);


        return json_decode($res,true);
    }
}
